#include<iostream>
#include<map>
#include<string>
using namespace std;
const int N = 110;
int a[N];
int n, m;
map<string, int>mp;
string s[N];
int main()
{
	cin >> n >> m;
	for (int i = 1; i <= n; i++) {
		cin >> s[i];
	}
	int ans = 0;
	string s1;
	for (int i = 1; i <= m; i++) {
		cin >> s1;
		mp[s1] = i;
	}
	for (int i = 0; i <= m; i++) {
		int x;
		cin >> a[i];
	}
	for (int i = 1; i <= n; i++) {
		if (mp[s[i]]) {
			ans += a[mp[s[i]]];
		}
		else ans += a[0];
	}
	cout << ans << endl;
	return 0;
}